package com.xzq.action;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.xzq.biz.UserBiz;
import com.xzq.entity.Page;
import com.xzq.entity.User;
@Controller
public class UserAction extends BaseAction {
	private User user;
	private Page page;
	private String time;
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	@Resource
	private UserBiz biz;
	
	
	public String regist(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date date = null;
		try {
			date = sdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Date d = new Date(date.getTime());
		user.setBirthday(d);
		int count = biz.addUser(user);
		if(count==1){
			return "login";
		}else{
			return "fail";
		}
	}
	
	public String login(){
		user = biz.findOneUser(user);
		session.put("user", user);
		if(user!=null){
			return "show";
		}else{
			return "fail";
		}
	}
}
